

from .celery import app


@app.task
def update_banner():
    from django.core.cache import cache
    from home.models import BannerModel
    from home.serializer import BannerSerializer
    from luffy.settings.dev import BONNER_COUNT
    queryset = BannerModel.objects.filter(
        is_delete=False, is_show=True).order_by("orders")[:BONNER_COUNT]
    serializer_banner = BannerSerializer(queryset, many=True)

    # 拼接图片url
    for banner in serializer_banner.data:
        banner['img']='http://127.0.0.1:8000'+banner['img']
    # 更新缓存
    cache.set('banner_list',serializer_banner.data, 60*60*24)
    return True
